package 力扣日常刷题.木23一月.第14天314;

import java.util.Deque;
import java.util.LinkedList;

/**
 * @author 帅小伙
 * @date 2022/3/14
 * @description
 * 单调栈
 */
public class Demo68每日温度 {

    public int[] dailyTemperatures(int[] temperatures) {
        int length = temperatures.length;
        int[] ans = new int[length];
        Deque<Integer> stack = new LinkedList<>();
        for (int i = 0; i < length; i++) {
            int t = temperatures[i];
            while(!stack.isEmpty() && t > temperatures[stack.peek()]) {
                int pre = stack.pop();
                ans[pre] = i - pre;
            }
            stack.push(i);
        }
        return ans;
    }

}
